using System;
using System.Collections;
using System.Windows.Forms;

namespace VSSDKAssist.Recipes.Common.Editors.Grid
{
    /// <summary/>
    public class ListBindingStrategy : IBindingStrategy
    {
        /// <summary/>
        private IList list;

        /// <summary>
        /// Initializes a new instance of the <see cref="T:ListBindingStrategy"/> class.
        /// </summary>
        /// <param name="list">The list.</param>
        public ListBindingStrategy(IList list)
        {
            this.list = list;
        }

        /// <summary>
        /// Gets the bound item.
        /// </summary>
        /// <param name="gridRow">The grid row.</param>
        /// <returns></returns>
        public object GetBoundItem(DataGridViewRow gridRow)
        {
            if(gridRow == null)
                throw new ArgumentNullException("gridRow");

            if(gridRow.Index >= 0 && gridRow.Index < list.Count)
                return list[gridRow.Index];
            else
                return null;
        }
    }
}
